/*
 * @copyright: Huang Ding
 * @Author: ding-cx
 * @Date: 2021-10-19 11:23:39
 * @LastEditors: ding-cx
 * @LastEditTime: 2022-06-15 16:41:24
 * @Description: file content
 */
import { actions } from "./actions";
import { hc } from "../hc";
import BaseHttpService from "./BaseHttpService";

/**
 * todo
 * 海清下发控制策略
 */
export default class StrategyService extends BaseHttpService {
	/** 下发一个策略 添加或修改 */
	async sendOneStrategy(strategy: hc.http.IRequestSendOneStrategyInfo) {
		const action = actions.AddAccessStrategy;
		const data = {
			info: strategy,
		};
		return await this.request<hc.http.IResponseSendOneStrategy>(action, data);
	}

	/** 查询设备的已有策略 */
	async getStrategies() {
		const action = actions.QueryAllStrategyID;
		const data = {
			info: {},
		};
		return await this.request<hc.http.IResponseGetStrategies>(action, data);
	}

	/** 查询策略详情 */
	async getOneStrategyDetail(ids: number[]) {
		const action = actions.AccessStrategyIDQueryStrategy;
		const data = {
			info: {
				strategyID: ids,
			},
		};
		return await this.request<hc.http.IResponseGetOneStrategyDetail>(action, data);
	}

	/** 查询策略关联的人员信息 */
	async getOneStrategyRelatePersonInfo(id: number) {
		const action = actions.AccessStrategyIDQueryPersons;
		const data = {
			info: {
				strategyID: id,
			},
		};
		return await this.request<hc.http.IResponseGetOneStrategyRelatePersonInfo>(action, data);
	}

	/** 删除策略 */
	async deleteStrategy(ids: number[]) {
		const action = actions.DelAccessStrategy;
		const data = {
			info: {
				strategyID: ids,
			},
		};
		return await this.request<hc.http.IResponseDeleteStrategy>(action, data);
	}

	/** 人员绑定到策略 */
	async bindPersonToStrategyByPersonUUID(arrs: { uuid: string; strategyId: number[] }[]) {
		const action = actions.PersonsBindStrategyID;
		const data = {
			info: {
				personsInfo: arrs.map((i) => ({ PersonUUID: i.uuid, strategyID: i.strategyId })),
			},
		};
		return await this.request<hc.http.IResponseBindPersonToStrategy>(action, data);
	}
	/** 人员绑定到策略 使用cusotmizeID */
	async bindPersonToStrategyByCustomizeID(arrs: { customId: number; strategyId: number[] }[]) {
		const action = actions.PersonsBindStrategyID;
		const data = {
			info: {
				personsInfo: arrs.map((i) => ({
					CustomizeID: i.customId,
					strategyID: i.strategyId,
				})),
			},
		};
		return await this.request<hc.http.IResponseBindPersonToStrategy>(action, data);
	}

	/** 人员解绑策略 */
	async unbindPersonToStrategyByPersonUUID(arrs: { uuid: string; strategyId: number[] }[]) {
		const action = actions.PersonsUnbindStrategyID;
		const data = {
			info: {
				personsInfo: arrs.map((i) => ({ PersonUUID: i.uuid, strategyID: i.strategyId })),
			},
		};
		return await this.request<hc.http.IResponseUnbindPersonToStrategy>(action, data);
	}
	/** 人员解绑策略 使用cusotmizeID */
	async unbindPersonToStrategyByCustomizeID(
		arrs: { customId: number; strategyId: number[] }[]
	) {
		const action = actions.PersonsUnbindStrategyID;
		const data = {
			info: {
				personsInfo: arrs.map((i) => ({
					CustomizeID: i.customId,
					strategyID: i.strategyId,
				})),
			},
		};
		return await this.request<hc.http.IResponseUnbindPersonToStrategy>(action, data);
	}
}
